<template>
	<gracePage :customHeader="false">
		<!-- 页面主体 -->
		<view slot="gBody">
			<common-item title="账号与安全" url="../update-password/update-password"></common-item>
			<common-item title="绑定邮箱" url="../update-email/update-email"></common-item>
			<common-item title="资料编辑" url="../update-user-info/update-user-info"></common-item>
			<common-item title="小纸条"></common-item>
			<common-item title="清除缓存" @click="clearCache">
				<text class="grace-black9">{{currentSize|format}}</text>
			</common-item>
			<common-item title="意见反馈" url="../suggest/suggest"></common-item>
			<common-item title="关于糗事百科" url="../about/about"></common-item>
			<button type="primary" @click.stop="logout">退出登录</button>
		</view>
	</gracePage>
</template>

<script>
	import CommonItem from '../../components/common-item/common-item'
	export default {
		data() {
			return {
				currentSize:0
			}
		},
		onLoad() {
			this.getStorageInfo();
		},
		filters:{
			format(value){
				return value > 1024 ? (value / 1024).toFixed(2) + 'MB' : value.toFixed(2) + 'KB';
			}
		},
		methods: {
			logout(){
				console.log('退出登录')
			},
			getStorageInfo(){
				this.currentSize = uni.getStorageInfoSync().currentSize
			},
			clearCache(){
				uni.showModal({
					title:"提示",
					content:"是否要清除缓存？",
					confirmText:"立刻清除",
					success:res=>{
						if(res.confirm){
							uni.clearStorageSync();
							this.getStorageInfo()
							uni.showToast({
								title:"清除缓存成功！"
							})
						}
					}
				})
			}
		},
		comments:{
			CommonItem
		}
	}
</script>

<style lang="stylus">
	button
		width 90%
		margin 30rpx auto
		color #333333 !important
		background #FFE934 !important
</style>
